<?php
class ConfigAction extends Action {

    protected $exceptedAction = array('login', 'logout');

    function __construct() {
        parent::__construct();
        
        // $this->checkLogIn();
        // $this->checkUserLevel();
    }
    
    // 检测用户是否登陆
    public function checkLogIn() {
        // 判断登陆
        if (!isset($_SESSION['user']) && !in_array(ACTION_NAME, $this->exceptedAction)) {
            // echo '<script type="text/javascript">window.parent.parent.location.href="' . U('User/login') . '"</script>';
            $this->assign('jumpUrl', U('User/login'));
            $this->error('您尚未登录，请先登录！');
            // $title = '尚未登陆！';
            // $error = '<a href="' . U('User/login') . '" target="_blank">如果页面未能跳转，请单击本链接。</a>';
            // $this->assign('title', $title);
            // $this->assign('error', $error);
            // $this->display('Public:error');
        }
    }
    
    // 检测用户权限
    public function checkUserLevel($arr) {
        if (!in_array($_SESSION['user']['user_type_id'], $arr) && !in_array(ACTION_NAME, $this->exceptedAction)) {
            $this->error('您没有权限！');
        }
    }
    
    public function checkTeacherArticle() {
        if ($_SESSION['user']['user_type_id'] == 3 && isset($_POST['cat_id']) && $_POST['cat_id'] != 29) {
            exit();
        }
        if ($_SESSION['user']['user_type_id'] == 3 && isset($_GET['id'])) {
            if ($article['cat_id'] != 29) {
                exit();
            }
        }
    }
    
    public function checkTeacherFile() {
        if ($_SESSION['user']['user_type_id'] == 3 && isset($_POST['cat_id']) && $_POST['cat_id'] != 30) {
            exit();
        }
        if ($_SESSION['user']['user_type_id'] == 3 && isset($_GET['id'])) {
            $id = (int) $_GET['id'];
            $File = M('File');
            $file = $File->find($id);
            if ($file['cat_id'] != 30) {
                exit();
            }
        }
    }
    
}
?>